Skip to main content

Database Entities

RatingAppointment

Represents a customer rating for an appointment including ratings for provider, staff, clinic, and overall.

ColumnTypeDescription
idnumberPrimary key, auto-generated identifier.
customerCustomerMany-to-one relation to the customer who gave the rating.
bookingIdstringUnique booking identifier (varchar 128). This is emrAppointmentId for external appointments.
businessLocationBusinessLocationMany-to-one relation to the business location rated.
agentAgentMany-to-one relation to the agent rated.
overallRatingfloatOverall rating score (default 0).
providerRatingfloatRating for the service provider (default 0).
staffRatingfloatRating for the staff (default 0).
clinicRatingfloatRating for the clinic (default 0).
commentsstringOptional comments provided by the customer (nullable).
tagsstringOptional tags related to the rating (nullable).
statusenumStatus of rating: pending, approved, or rejected.
datetimeRatedtimestampTimestamp when the rating was created.
approvedByAgentAgent who approved or rejected the rating (nullable).
datetimeApprovedtimestampTimestamp when the rating was approved or rejected (nullable).

Unique Constraints

  • bookingId must be unique across ratings.

Methods

  • approve(agent: Agent): Marks rating as approved by the given agent with timestamp.
  • reject(agent: Agent): Marks rating as rejected by the given agent with timestamp.

RatingClinic

Represents aggregate rating data for a business location's clinic.

ColumnTypeDescription
idnumberPrimary key, auto-generated identifier.
businessLocationBusinessLocationMany-to-one relation to the business location.
overallRatingfloatSum of all overall ratings for the clinic.
overallCountintNumber of ratings submitted.

Computed Property

  • averageRating: Returns average rating as overallRating / overallCount or 0 if count is 0.

RatingProvider

Represents aggregate rating data for a service provider (agent) at a business location.

ColumnTypeDescription
idnumberPrimary key, auto-generated identifier.
businessLocationBusinessLocationMany-to-one relation to business location.
agentAgentMany-to-one relation to the agent (provider).
overallRatingfloatSum of all overall ratings for the provider.
overallCountintNumber of ratings submitted.
tagsstringOptional tags related to ratings (nullable).

Computed Property

  • averageRating: Returns average rating as overallRating / overallCount or 0 if count is 0.

RatingStaff

Represents aggregate rating data for staff at a business location.

ColumnTypeDescription
idnumberPrimary key, auto-generated identifier.
businessLocationBusinessLocationMany-to-one relation to business location.
overallRatingfloatSum of all overall ratings for the staff.
overallCountintNumber of ratings submitted.
tagsstringOptional tags related to ratings (nullable).

Computed Property

  • averageRating: Returns average rating as overallRating / overallCount or 0 if count is 0.

RatingNotification

Represents notifications sent regarding rating requests or reminders for appointments.

ColumnTypeDescription
idnumberPrimary key, auto-generated identifier.
appointmentIdbigintAppointment identifier linked to the notification.
isInternalbooleanFlag indicating if appointment is internal or not.
typeNotificationTypeEnum defining notification type (e.g. email, sms).
cycleTypeNotificationCycleTypeEnum defining notification cycle: initial, reminder1, reminder2.
statusNotificationStatusStatus of notification: OPEN(opn), RATED(rtd), CANCELLED(cxl).
customerCustomerMany-to-one relation to the customer (nullable).
sentAttimestampTimestamp when notification was sent (nullable).

Unique Constraints

  • Unique combination of (appointmentId, type, cycleType) to avoid duplicate notifications.

Utility: averageRating

Helper function to calculate average rating given sum and count.

export const averageRating = (rating: number, count: number) => {
return count > 0 ? rating / count : 0;
};